package top.byfree.jbyan.find.command;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jbyan
 * @since 2023/8/3
 */
public enum Arg {
    RANGE("-range", new String[]{}, 1, 200, "--range [size] 检索两个关键字时，允许两关键字间隔的最大行数，默认200"),
    ENCODING("-encoding", new String[]{"e"}, 1, "UTF-8", "--encoding [coding] 指定编码，默认UTF-8"),
    OUT("-out", new String[]{"o"}, 1, System.getProperty("user.dir"), "--out [目录] 指定输出结果的目录，默认不输出，不指定目录默认为当前目录"),
    RESULT_MESSAGE("-result_message", new String[]{"r"}, 1, "simple", "-result_message 是否在控制台打印检索到的行"),
    DIRECTORY("-directory", new String[]{"d"}, 1, System.getProperty("user.dir"), "--directory  <目录> 指定检索的目录，默认当前目录"),
    DEPTH("-depth", new String[]{}, 1, Integer.MAX_VALUE, "--depth [size] 指定检索目录时，递归遍历目录的最大深度，默认Integer.MAX_VALUE"),
    THREAD_POOL("-thread_pool", new String[]{}, 1, 6, "--thread_pool [size] 指定遍历时启用的线程数量，默认6"),
    BINARY("-binary", new String[]{"b"}, 0, false, "--binary 是否检索二进制文件，默认不检索"),
    PLURAL("-plural", new String[]{"p"}, 0, false, "--plural 是否是检索两个关键字，不指定为检索一个关键字"),
    RESULT_ALL("-result_all", new String[]{"a"}, 0, false, "--result_all 是否显示未命中的文件结果"),
    HELP("-help", new String[]{}, 0, false, "--help 显示帮助文档")
    ;

    public static Arg findArg(String arg) {
        Arg[] values = Arg.values();
        List<Arg> collect = Arrays.stream(values)
                .filter(item -> item.name.equals(arg) || Arrays.asList(item.alias).contains(arg))
                .collect(Collectors.toList());
        if (collect.size() == 1) {
            return collect.get(0);
        }
        return null;
    }

    private final String name;

    private final String[] alias;
    // 参数数量
    private final int size;

    private final Object defaultVal;

    private final String remark;

    Arg(String name, String[] alias, int size, Object defaultVal, String remark) {
        this.name = name;
        this.alias = alias;
        this.size = size;
        this.defaultVal = defaultVal;
        this.remark = remark;
    }

    public String getName() {
        return name;
    }

    public String[] getAlias() {
        return alias;
    }

    public int getSize() {
        return size;
    }

    public Object getDefaultVal() {
        return defaultVal;
    }

    public String getRemark() {
        return remark;
    }
}
